﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MotionControl;
using WHW_NetUtility;
using System.Diagnostics;
using System.Threading;
using System.Windows.Forms;
using System.IO;
using HalconDotNet;
using Newtonsoft.Json;
using System.Text.RegularExpressions;
using XXTUserUI;

namespace MainFrame
{
    public partial class GlobalMotion
    {
        /// <summary>
        /// 撕膜
        /// </summary>
        public static void Task_Cuting()
        {
            try
            {
                e_platePro e_CurPlate = e_platePro.双平台无;
                string logFlow = e_Cut.ToString();
                bool IsCutOver = false;///是否执行过撕膜
                bool isUse = false;
                while (!GlobalVar.isExit)
                {

                    Thread.Sleep(2);
                    if (!GlobalVar.isEstop)
                    {
                        if (GlobalVar.isAutoRun)
                        {
                            if (GlobalVar.IsStart_EndWork)
                            {
                                e_Cut = e_Flow_Cut.等待有工装到达;
                                continue;
                            }
                            var IsHavePro1 = !Input_CardEx2[(int)e_input_extCard2.上输送产品检测1];
                            var IsHavePro2 = !Input_CardEx2[(int)e_input_extCard2.上输送产品检测2];

                            switch (e_Cut)
                            {
                                case e_Flow_Cut.等待有工装到达:
                                    if (GlobalVar.Cut_Start || GlobalVar.IsOldTest || (CMachine.Instance.IsTestModel))
                                    {
                                        IsCutOver = false;
                                        GlobalVar.Cut_Start = false;
                                        if ((IsHavePro1 || IsHavePro2) || CMachine.Instance.IsTestModel)
                                        {
                                            if (IsHavePro1 && !IsHavePro2)
                                                e_CurPlate = e_platePro.平台1;
                                            else if (!IsHavePro1 && IsHavePro2)
                                                e_CurPlate = e_platePro.平台2;
                                            else if (IsHavePro1 && IsHavePro2 || CMachine.Instance.IsTestModel)
                                                e_CurPlate = e_platePro.双平台有;
                                            e_Cut = e_Flow_Cut.读卡器读数据;
                                        }
                                        else
                                        {
                                            e_Cut = e_Flow_Cut.放行治具;
                                        }
                                    }
                                    break;
                                case e_Flow_Cut.读卡器读数据:
                                    {
                                        var RFIDinfo = GlobalVar.userConfig.RFIDBox;
                                        #region 老RFID
                                        //if (!RFIDinfo.IsEnableRFID)
                                        //{
                                        //    var BoxInfo = GlobalVar.motionConfig.boxReadInfo;
                                        //    if (BoxInfo.IsEnable)
                                        //    {
                                        //        if (e_CurPlate == e_platePro.双平台有)
                                        //        {
                                        //            var isSuccess1 = true;
                                        //            var isSuccess2 = true;
                                        //            var pro1 = GlobalVar.Box1.ReadBoxString(BoxInfo.StartAddress1, BoxInfo.dataLength, BoxInfo.station, BoxInfo.IsReadWriteOK, BoxInfo.nTimes);
                                        //            var pro2 = GlobalVar.Box1.ReadBoxString(BoxInfo.StartAddress2, BoxInfo.dataLength, BoxInfo.station, BoxInfo.IsReadWriteOK, BoxInfo.nTimes);
                                        //            for (int nr = 0; nr < BoxInfo.nTimes; nr++)
                                        //            {
                                        //                if (!string.IsNullOrEmpty(pro1) && pro1.Length >= (BoxInfo.minLength))
                                        //                {
                                        //                    isSuccess1 = checkString(pro1, BoxInfo) == 1;
                                        //                    if (isSuccess1)
                                        //                        break;
                                        //                    else
                                        //                    {
                                        //                        displalyInfo.displayInfoMain($"读卡器1内容不合预期:{pro1}第{nr}次");
                                        //                        pro1 = GlobalVar.Box1.ReadBoxString(BoxInfo.StartAddress1, BoxInfo.dataLength, BoxInfo.station, BoxInfo.IsReadWriteOK);
                                        //                    }
                                        //                }
                                        //                else
                                        //                {
                                        //                    displalyInfo.displayInfoMain($"读卡器1内容不合预期:{pro1}第{nr}次");
                                        //                    pro1 = GlobalVar.Box1.ReadBoxString(BoxInfo.StartAddress1, BoxInfo.dataLength, BoxInfo.station, BoxInfo.IsReadWriteOK);
                                        //                }
                                        //            }
                                        //            for (int nr = 0; nr < BoxInfo.nTimes; nr++)
                                        //            {
                                        //                if (!string.IsNullOrEmpty(pro2) && pro2.Length >= (BoxInfo.minLength))
                                        //                {
                                        //                    isSuccess2 = checkString(pro2, BoxInfo) == 1;
                                        //                    if (isSuccess2)
                                        //                        break;
                                        //                    else
                                        //                    {
                                        //                        displalyInfo.displayInfoMain($"读卡器2内容不合预期:{pro2}第{nr}次");
                                        //                        pro2 = GlobalVar.Box1.ReadBoxString(BoxInfo.StartAddress2, BoxInfo.dataLength, BoxInfo.station, BoxInfo.IsReadWriteOK);
                                        //                    }
                                        //                }
                                        //                else
                                        //                {
                                        //                    displalyInfo.displayInfoMain($"读卡器2内容不合预期:{pro2}第{nr}次");
                                        //                    pro2 = GlobalVar.Box1.ReadBoxString(BoxInfo.StartAddress2, BoxInfo.dataLength, BoxInfo.station, BoxInfo.IsReadWriteOK);
                                        //                }
                                        //            }
                                        //            var IsPro1OK = !string.IsNullOrEmpty(pro1) && pro1.Length >= (BoxInfo.minLength) && !pro1.Contains(BoxInfo.NGflag);
                                        //            var IsPro2OK = !string.IsNullOrEmpty(pro2) && pro2.Length >= (BoxInfo.minLength) && !pro2.Contains(BoxInfo.NGflag);
                                        //            if (IsPro1OK || IsPro2OK)
                                        //            {
                                        //                displalyInfo.displayInfoMain($"读卡器1:{pro1} 读卡器2:{pro2}");

                                        //                if (GlobalVar.Laser_pros.Count == 0)
                                        //                {
                                        //                    if (GlobalVar.front_pros.Count == 0)
                                        //                    {
                                        //                        GlobalVar.front_pros.Add(new ProductInfo()
                                        //                        {
                                        //                            LaserTime = DateTime.Now,
                                        //                            typeName = GlobalVar.closeSave.CurrentTypeName,
                                        //                            ProNo = 1,
                                        //                            Result_up = e_Result.进料OK.ToString()
                                        //                        });
                                        //                        GlobalVar.front_pros.Add(new ProductInfo()
                                        //                        {
                                        //                            LaserTime = DateTime.Now,
                                        //                            typeName = GlobalVar.closeSave.CurrentTypeName,
                                        //                            ProNo = 2,
                                        //                            Result_up = e_Result.进料OK.ToString()
                                        //                        });
                                        //                    }
                                        //                    GlobalVar.Laser_pros = GlobalVar.front_pros.Take(2).ToList();
                                        //                    GlobalVar.front_pros.Clear();
                                        //                }
                                        //                if (!string.IsNullOrEmpty(pro1) && pro1.Length >= (BoxInfo.minLength) && !pro1.Contains(BoxInfo.NGflag))
                                        //                {

                                        //                    GlobalVar.Laser_pros.ForEach(a =>
                                        //                    {
                                        //                        if (a.ProNo == 1)
                                        //                        {
                                        //                            a.ProId = pro1;
                                        //                            if (!isSuccess1)
                                        //                                a.Result_up = e_Result.进料读卡NG.ToString();
                                        //                        }
                                        //                    });

                                        //                }
                                        //                else
                                        //                {
                                        //                    GlobalVar.Laser_pros.ForEach(a =>
                                        //                    {
                                        //                        if (a.ProNo == 1)
                                        //                        {
                                        //                            a.ProId = pro1;
                                        //                            a.Result_up = e_Result.进料读卡NG.ToString();
                                        //                        }
                                        //                    });
                                        //                }
                                        //                if (!string.IsNullOrEmpty(pro2) && pro2.Length >= (BoxInfo.minLength) && !pro2.Contains(BoxInfo.NGflag))
                                        //                {

                                        //                    GlobalVar.Laser_pros.ForEach(a =>
                                        //                    {
                                        //                        if (a.ProNo == 2)
                                        //                        {
                                        //                            a.ProId = pro2;
                                        //                            if (!isSuccess2)
                                        //                                a.Result_up = e_Result.进料读卡NG.ToString();
                                        //                        }
                                        //                    });
                                        //                }
                                        //                else
                                        //                {
                                        //                    GlobalVar.Laser_pros.ForEach(a =>
                                        //                    {
                                        //                        if (a.ProNo == 2)
                                        //                        {
                                        //                            a.ProId = pro2;
                                        //                            a.Result_up = e_Result.进料读卡NG.ToString();
                                        //                        }
                                        //                    });
                                        //                }
                                        //                var NGpro = GlobalVar.Laser_pros.Where(A => A.Result_up.Contains("NG")).ToArray();
                                        //                if (NGpro == null || NGpro.Length == 0)
                                        //                {
                                        //                    e_CurPlate = e_platePro.双平台有;
                                        //                    e_Cut = e_Flow_Cut.撕膜;
                                        //                }
                                        //                else if (NGpro.Length == 1)
                                        //                {
                                        //                    if (NGpro[0].ProNo == 1)
                                        //                        e_CurPlate = e_platePro.平台2;
                                        //                    else
                                        //                        e_CurPlate = e_platePro.平台1;
                                        //                    e_Cut = e_Flow_Cut.撕膜;
                                        //                }
                                        //                else if (NGpro.Length == 2)
                                        //                {
                                        //                    e_Cut = e_Flow_Cut.放行治具;
                                        //                }

                                        //            }
                                        //            else
                                        //            {
                                        //                displalyInfo.displayInfoMain($"读卡器1内容不合预期:{pro1} 读卡器2内容不合预期:{pro2}");
                                        //                GlobalVar.Laser_pros.ForEach(a =>
                                        //                {
                                        //                    if (a.ProNo == 1)
                                        //                    {
                                        //                        a.ProId = pro1;
                                        //                        a.Result_up = e_Result.进料读卡NG.ToString();
                                        //                    }
                                        //                    if (a.ProNo == 2)
                                        //                    {
                                        //                        a.ProId = pro2;
                                        //                        a.Result_up = e_Result.进料读卡NG.ToString();
                                        //                    }
                                        //                }
                                        //                );
                                        //                e_Cut = e_Flow_Cut.放行治具;
                                        //            }
                                        //            if (GlobalVar.userConfig.UploadInfo.IsUploadUrl)
                                        //            {
                                        //                if (!string.IsNullOrEmpty(GlobalVar.userConfig.UploadInfo.url_CheckUpload))
                                        //                {
                                        //                    UploadInterface.upload_CheckUpload(pro1);
                                        //                    UploadInterface.upload_CheckUpload(pro2);
                                        //                }
                                        //            }
                                        //        }
                                        //        else if (e_CurPlate == e_platePro.平台1)
                                        //        {
                                        //            var isSuccess1 = true;
                                        //            if (GlobalVar.Laser_pros.Count == 0)
                                        //            {
                                        //                if (GlobalVar.front_pros.Count == 0)
                                        //                {
                                        //                    GlobalVar.front_pros.Add(new ProductInfo()
                                        //                    {
                                        //                        LaserTime = DateTime.Now,
                                        //                        typeName = GlobalVar.closeSave.CurrentTypeName,
                                        //                        ProNo = 1,
                                        //                        Result_up = e_Result.进料OK.ToString()
                                        //                    });

                                        //                }
                                        //                GlobalVar.Laser_pros = GlobalVar.front_pros.Take(1).ToList();
                                        //                GlobalVar.front_pros.Clear();
                                        //            }
                                        //            var pro1 = GlobalVar.Box1.ReadBoxString(BoxInfo.StartAddress1, BoxInfo.dataLength, BoxInfo.station, BoxInfo.IsReadWriteOK);
                                        //            for (int nr = 0; nr < BoxInfo.nTimes; nr++)
                                        //            {
                                        //                if (!string.IsNullOrEmpty(pro1) && pro1.Length >= (BoxInfo.minLength))
                                        //                {
                                        //                    isSuccess1 = checkString(pro1, BoxInfo) == 1;
                                        //                    if (isSuccess1)
                                        //                        break;
                                        //                    else
                                        //                    {
                                        //                        displalyInfo.displayInfoMain($"读卡器1内容不合预期:{pro1}第{nr}次");
                                        //                        pro1 = GlobalVar.Box1.ReadBoxString(BoxInfo.StartAddress1, BoxInfo.dataLength, BoxInfo.station, BoxInfo.IsReadWriteOK);
                                        //                    }
                                        //                }
                                        //                else
                                        //                {
                                        //                    displalyInfo.displayInfoMain($"读卡器1内容不合预期:{pro1}第{nr}次");
                                        //                    pro1 = GlobalVar.Box1.ReadBoxString(BoxInfo.StartAddress1, BoxInfo.dataLength, BoxInfo.station, BoxInfo.IsReadWriteOK);
                                        //                }
                                        //            }
                                        //            if (!string.IsNullOrEmpty(pro1) && pro1.Length >= (BoxInfo.minLength) && !pro1.Contains(BoxInfo.NGflag))
                                        //            {
                                        //                displalyInfo.displayInfoMain($"读卡器1内容:{pro1}");
                                        //                GlobalVar.Laser_pros.ForEach(a =>
                                        //                {
                                        //                    if (a.ProNo == 1)
                                        //                    {
                                        //                        a.ProId = pro1;
                                        //                        if (!isSuccess1)
                                        //                            a.Result_up = e_Result.进料读卡NG.ToString();
                                        //                    }
                                        //                });
                                        //                e_Cut = e_Flow_Cut.撕膜;

                                        //            }
                                        //            else
                                        //            {
                                        //                displalyInfo.displayInfoMain($"读卡器1内容不合预期:{pro1}");

                                        //                GlobalVar.Laser_pros.ForEach(a =>
                                        //                {
                                        //                    if (a.ProNo == 1)
                                        //                    {
                                        //                        a.ProId = pro1;
                                        //                        a.Result_up = e_Result.进料读卡NG.ToString();
                                        //                    }

                                        //                }
                                        //                );
                                        //                e_Cut = e_Flow_Cut.放行治具;

                                        //            }
                                        //            if (GlobalVar.userConfig.UploadInfo.IsUploadUrl)
                                        //            {
                                        //                if (!string.IsNullOrEmpty(GlobalVar.userConfig.UploadInfo.url_CheckUpload))
                                        //                {
                                        //                    UploadInterface.upload_CheckUpload(pro1);

                                        //                }
                                        //            }
                                        //        }
                                        //        else if (e_CurPlate == e_platePro.平台2)
                                        //        {
                                        //            var isSuccess2 = true;
                                        //            var pro2 = GlobalVar.Box1.ReadBoxString(BoxInfo.StartAddress2, BoxInfo.dataLength, BoxInfo.station, BoxInfo.IsReadWriteOK);
                                        //            for (int nr = 0; nr < BoxInfo.nTimes; nr++)
                                        //            {
                                        //                if (!string.IsNullOrEmpty(pro2) && pro2.Length >= (BoxInfo.minLength))
                                        //                {
                                        //                    isSuccess2 = checkString(pro2, BoxInfo) == 1;
                                        //                    if (isSuccess2)
                                        //                        break;
                                        //                    else
                                        //                    {
                                        //                        displalyInfo.displayInfoMain($"读卡器2内容不合预期:{pro2}第{nr}次");
                                        //                        pro2 = GlobalVar.Box1.ReadBoxString(BoxInfo.StartAddress2, BoxInfo.dataLength, BoxInfo.station, BoxInfo.IsReadWriteOK);
                                        //                    }
                                        //                }
                                        //                else
                                        //                {
                                        //                    displalyInfo.displayInfoMain($"读卡器2内容不合预期:{pro2}第{nr}次");
                                        //                    pro2 = GlobalVar.Box1.ReadBoxString(BoxInfo.StartAddress2, BoxInfo.dataLength, BoxInfo.station, BoxInfo.IsReadWriteOK);
                                        //                }
                                        //            }
                                        //            if (GlobalVar.Laser_pros.Count == 0)
                                        //            {
                                        //                if (GlobalVar.front_pros.Count == 0)
                                        //                {
                                        //                    GlobalVar.front_pros.Add(new ProductInfo()
                                        //                    {
                                        //                        LaserTime = DateTime.Now,
                                        //                        typeName = GlobalVar.closeSave.CurrentTypeName,
                                        //                        ProNo = 2,
                                        //                        Result_up = e_Result.进料OK.ToString()
                                        //                    });

                                        //                }
                                        //                GlobalVar.Laser_pros = GlobalVar.front_pros.Take(2).ToList();
                                        //                GlobalVar.front_pros.Clear();
                                        //            }
                                        //            if (!string.IsNullOrEmpty(pro2) && pro2.Length >= (BoxInfo.minLength) && !pro2.Contains(BoxInfo.NGflag))
                                        //            {
                                        //                displalyInfo.displayInfoMain($"读卡器1内容:{pro2}");
                                        //                GlobalVar.Laser_pros.ForEach(a =>
                                        //                {
                                        //                    if (a.ProNo == 2)
                                        //                    {
                                        //                        a.ProId = pro2;
                                        //                        if (!isSuccess2)
                                        //                            a.Result_up = e_Result.进料读卡NG.ToString();
                                        //                    }
                                        //                });
                                        //                e_Cut = e_Flow_Cut.撕膜;
                                        //            }
                                        //            else
                                        //            {
                                        //                displalyInfo.displayInfoMain($" 读卡器2内容不合预期:{pro2}");
                                        //                GlobalVar.Laser_pros.ForEach(a =>
                                        //                {
                                        //                    if (a.ProNo == 2)
                                        //                    {
                                        //                        a.ProId = pro2;
                                        //                        a.Result_up = e_Result.进料读卡NG.ToString();
                                        //                    }
                                        //                }
                                        //                );
                                        //                e_Cut = e_Flow_Cut.放行治具;
                                        //            }
                                        //            if (GlobalVar.userConfig.UploadInfo.IsUploadUrl)
                                        //            {
                                        //                if (!string.IsNullOrEmpty(GlobalVar.userConfig.UploadInfo.url_CheckUpload))
                                        //                {
                                        //                    UploadInterface.upload_CheckUpload(pro2);

                                        //                }
                                        //            }
                                        //        }
                                        //    }
                                        //    else
                                        //        e_Cut = e_Flow_Cut.撕膜;
                                        //}
                                        //else
                                        #endregion
                                        {
                                            if (RFIDinfo.IsEnable && !CMachine.Instance.IsTestModel)
                                            {
                                                if (e_CurPlate == e_platePro.双平台有)
                                                {
                                                    var resRFID = GlobalVar.RFIDBox_in.ReadRFID(RFIDinfo.station, GlobalVar.motionConfig.rfid_mode);
                                                    var pro1 = "";
                                                    var pro2 = "";
                                                    bool IsProOK1 = false;
                                                    bool IsProOK2 = false;
                                                    if (resRFID != null && resRFID.arr_Rfid != null && resRFID.arr_Rfid.Length == 2)
                                                    {
                                                        pro1 = resRFID.arr_Rfid[(int)e_RFIDPlate.产品1];
                                                        pro2 = resRFID.arr_Rfid[(int)e_RFIDPlate.产品2];
                                                        if (resRFID.Check_state != null && resRFID.Check_state.Length == 2)
                                                        {
                                                            IsProOK1 = resRFID.Check_state[(int)e_RFIDPlate.产品1];
                                                            IsProOK2 = resRFID.Check_state[(int)e_RFIDPlate.产品2];
                                                        }
                                                    }

                                                    for (int nr = 0; nr < RFIDinfo.nReadTimes; nr++)
                                                    {
                                                        if (!string.IsNullOrEmpty(pro1))
                                                            break;
                                                        else
                                                        {
                                                            displalyInfo.displayInfoMain($"进料读卡器产品1不合预期:{pro1}第{nr}次");
                                                            resRFID = GlobalVar.RFIDBox_in.ReadRFID(RFIDinfo.station, GlobalVar.motionConfig.rfid_mode);
                                                            if (resRFID != null && resRFID.arr_Rfid != null && resRFID.arr_Rfid.Length == 2)
                                                            {
                                                                pro1 = resRFID.arr_Rfid[(int)e_RFIDPlate.产品1];
                                                                if (resRFID.Check_state != null && resRFID.Check_state.Length == 2)
                                                                    IsProOK1 = resRFID.Check_state[(int)e_RFIDPlate.产品1];
                                                            }
                                                        }
                                                    }
                                                    for (int nr = 0; nr < RFIDinfo.nReadTimes; nr++)
                                                    {
                                                        if (!string.IsNullOrEmpty(pro2))
                                                            break;
                                                        else
                                                        {
                                                            displalyInfo.displayInfoMain($"进料读卡器产品2不合预期:{pro2}第{nr}次");
                                                            resRFID = GlobalVar.RFIDBox_in.ReadRFID(RFIDinfo.station, GlobalVar.motionConfig.rfid_mode);
                                                            if (resRFID != null && resRFID.arr_Rfid != null && resRFID.arr_Rfid.Length == 2)
                                                            {
                                                                pro2 = resRFID.arr_Rfid[(int)e_RFIDPlate.产品2];
                                                                if (resRFID.Check_state != null && resRFID.Check_state.Length == 2)
                                                                    IsProOK2 = resRFID.Check_state[(int)e_RFIDPlate.产品2];
                                                            }
                                                        }
                                                    }
                                                    if (IsProOK1 && IsProOK2)
                                                    {
                                                        var msg_Rfid = $"读卡器1:{pro1} 读卡器2:{pro2}";
                                                        var resRfid = GlobalVar.RFIDBox_in.ReadRFID_Clear(new string[] { pro1, pro2 });
                                                        if (resRfid != null && resRfid.isClear)
                                                        {
                                                            GlobalVar.IsEndWork = true;
                                                            msg_Rfid += "结束作业";
                                                        }
                                                        displalyInfo.displayInfoMain(msg_Rfid);
                                                    }
                                                    else if (IsProOK1)
                                                    {
                                                        var msg_Rfid = $"读卡器1:{pro1} ";
                                                        var resRfid = GlobalVar.RFIDBox_in.ReadRFID_Clear(new string[] { pro1, pro1 });
                                                        if (resRfid != null && resRfid.isClear)
                                                        {
                                                            GlobalVar.IsEndWork = true;
                                                            msg_Rfid += "结束作业";
                                                        }
                                                        displalyInfo.displayInfoMain(msg_Rfid);
                                                    }
                                                    else if (IsProOK2)
                                                    {
                                                        var msg_Rfid = $"读卡器2:{pro2} ";
                                                        var resRfid = GlobalVar.RFIDBox_in.ReadRFID_Clear(new string[] { pro2, pro2 });
                                                        if (resRfid != null && resRfid.isClear)
                                                        {
                                                            GlobalVar.IsEndWork = true;
                                                            msg_Rfid += "结束作业";
                                                        }
                                                        displalyInfo.displayInfoMain(msg_Rfid);
                                                    }
                                                    var IsPro1OK = !string.IsNullOrEmpty(pro1) && !pro1.Contains(RFIDinfo.NGflag) && IsProOK1;
                                                    var IsPro2OK = !string.IsNullOrEmpty(pro2) && !pro2.Contains(RFIDinfo.NGflag) && IsProOK2;
                                                    displalyInfo.displayInfoMain($"进料读卡器产品1:{pro1} 进料读卡器产品2:{pro2}");

                                                    GlobalVar.Laser_pros.ForEach(a =>
                                                    {
                                                        if (a.ProNo == 1)
                                                        {
                                                            a.ProId = pro1;
                                                            if (!IsPro1OK)
                                                            {
                                                                a.Result_up = e_Result.进料读卡NG.ToString();
                                                            }
                                                        }
                                                        if (a.ProNo == 2)
                                                        {
                                                            a.ProId = pro2;
                                                            if (!IsPro2OK)
                                                            {
                                                                a.Result_up = e_Result.进料读卡NG.ToString();
                                                            }
                                                        }
                                                    });
                                                    if (GlobalVar.userConfig.UploadInfo.IsUploadUrl)
                                                    {//进站数据上传
                                                        if (!string.IsNullOrEmpty(GlobalVar.userConfig.UploadInfo.url_CheckUpload))
                                                        {
                                                            UploadInterface.upload_CheckUpload(pro1);
                                                            UploadInterface.upload_CheckUpload(pro2);
                                                        }
                                                    }

                                                    if (GlobalVar.Laser_pros.Where(a => a.Result_up.Contains("NG")).Count() > 1)///单平台2+平台1读卡NG
                                                    {//治具顶起，没有物料
                                                        e_Cut = e_Flow_Cut.放行治具;
                                                    }
                                                    else
                                                    {
                                                        for (int i = 0; i < GlobalVar.Laser_pros.Count; i++)
                                                        {
                                                            if (GlobalVar.Laser_pros[i].Result_up.Contains("NG"))
                                                            {
                                                                GlobalVar.Laser_pros[i].Result_Cut = e_Result.撕膜NG.ToString();
                                                                if (GlobalVar.Laser_pros[i].ProNo == 2)
                                                                {
                                                                    displalyInfo.displayInfoMain($"进料RFID{GlobalVar.Laser_pros[i].ProId}异常  只撕膜平台1");
                                                                    e_CurPlate = e_platePro.平台1;
                                                                }
                                                                else
                                                                {
                                                                    displalyInfo.displayInfoMain($"进料RFID{GlobalVar.Laser_pros[i].ProId}异常  只撕膜平台2");
                                                                    e_CurPlate = e_platePro.平台2;
                                                                }
                                                            }
                                                        }
                                                        e_Cut = e_Flow_Cut.撕膜;
                                                    }

                                                }
                                                else if (e_CurPlate == e_platePro.平台1)
                                                {
                                                    var resRFID = GlobalVar.RFIDBox_in.ReadRFID(RFIDinfo.station, GlobalVar.motionConfig.rfid_mode);
                                                    var pro1 = "";
                                                    bool IsProOK1 = false;
                                                    if (resRFID != null && resRFID.arr_Rfid != null && resRFID.arr_Rfid.Length == 2)
                                                    {
                                                        pro1 = resRFID.arr_Rfid[(int)e_RFIDPlate.产品1];
                                                        if (resRFID.Check_state != null && resRFID.Check_state.Length == 2)
                                                            IsProOK1 = resRFID.Check_state[(int)e_RFIDPlate.产品1];
                                                    }
                                                    for (int nr = 0; nr < RFIDinfo.nReadTimes; nr++)
                                                    {
                                                        if (!string.IsNullOrEmpty(pro1))
                                                            break;
                                                        else
                                                        {
                                                            displalyInfo.displayInfoMain($"进料读卡器产品1不合预期:{pro1}第{nr}次");
                                                            resRFID = GlobalVar.RFIDBox_in.ReadRFID(RFIDinfo.station, GlobalVar.motionConfig.rfid_mode);
                                                            if (resRFID != null && resRFID.arr_Rfid != null && resRFID.arr_Rfid.Length == 2)
                                                            {
                                                                pro1 = resRFID.arr_Rfid[(int)e_RFIDPlate.产品1];
                                                                if (resRFID.Check_state != null && resRFID.Check_state.Length == 2)
                                                                    IsProOK1 = resRFID.Check_state[(int)e_RFIDPlate.产品1];
                                                            }
                                                        }
                                                    }
                                                    var msg_Rfid = $"进料读卡器产品1:{pro1}";
                                                    if (IsProOK1)
                                                    {
                                                        var resRfid = GlobalVar.RFIDBox_in.ReadRFID_Clear(new string[] { pro1, pro1 });
                                                        if (resRfid != null && resRfid.isClear)
                                                        {
                                                            GlobalVar.IsEndWork = true;
                                                            msg_Rfid += "结束作业";
                                                        }
                                                    }
                                                    var IsPro1OK = !string.IsNullOrEmpty(pro1) && !pro1.Contains(RFIDinfo.NGflag) && IsProOK1;

                                                    displalyInfo.displayInfoMain(msg_Rfid);
                                                    GlobalVar.Laser_pros.ForEach(a =>
                                                    {
                                                        if (a.ProNo == 1)
                                                        {
                                                            a.ProId = pro1;
                                                            if (!IsPro1OK)
                                                            {
                                                                a.Result_up = e_Result.进料读卡NG.ToString();
                                                            }
                                                        }
                                                    });
                                                    if (GlobalVar.userConfig.UploadInfo.IsUploadUrl)
                                                    {
                                                        if (!string.IsNullOrEmpty(GlobalVar.userConfig.UploadInfo.url_CheckUpload))
                                                        {
                                                            UploadInterface.upload_CheckUpload(pro1);

                                                        }
                                                    }
                                                    if (GlobalVar.Laser_pros.Where(a => a.Result_up.Contains("NG") && a.ProNo == 1).FirstOrDefault() != null)///单平台1+平台1读卡NG
                                                        e_Cut = e_Flow_Cut.放行治具;
                                                    else
                                                    {

                                                        e_Cut = e_Flow_Cut.撕膜;
                                                    }
                                                }
                                                else if (e_CurPlate == e_platePro.平台2)
                                                {
                                                    var resRFID = GlobalVar.RFIDBox_in.ReadRFID(RFIDinfo.station, GlobalVar.motionConfig.rfid_mode);
                                                    var pro2 = "";
                                                    bool IsProOK2 = false;
                                                    if (resRFID != null && resRFID.arr_Rfid != null && resRFID.arr_Rfid.Length == 2)
                                                    {
                                                        pro2 = resRFID.arr_Rfid[(int)e_RFIDPlate.产品2];
                                                        if (resRFID.Check_state != null && resRFID.Check_state.Length == 2)
                                                            IsProOK2 = resRFID.Check_state[(int)e_RFIDPlate.产品2];
                                                    }
                                                    for (int nr = 0; nr < RFIDinfo.nReadTimes; nr++)
                                                    {
                                                        if (!string.IsNullOrEmpty(pro2))
                                                            break;
                                                        else
                                                        {
                                                            displalyInfo.displayInfoMain($"进料读卡器产品2不合预期:{pro2}第{nr}次");
                                                            resRFID = GlobalVar.RFIDBox_in.ReadRFID(RFIDinfo.station, GlobalVar.motionConfig.rfid_mode);
                                                            if (resRFID != null && resRFID.arr_Rfid != null && resRFID.arr_Rfid.Length == 2)
                                                            {
                                                                pro2 = resRFID.arr_Rfid[(int)e_RFIDPlate.产品2];
                                                                if (resRFID.Check_state != null && resRFID.Check_state.Length == 2)
                                                                    IsProOK2 = resRFID.Check_state[(int)e_RFIDPlate.产品2];
                                                            }
                                                        }
                                                    }
                                                    var msg_Rfid = $"进料读卡器产品2:{pro2}";
                                                    if (IsProOK2)
                                                    {
                                                        var resRfid = GlobalVar.RFIDBox_in.ReadRFID_Clear(new string[] { pro2, pro2 });
                                                        if (resRfid != null && resRfid.isClear)
                                                        {
                                                            GlobalVar.IsEndWork = true;
                                                            msg_Rfid += "结束作业";
                                                        }
                                                    }
                                                    var IsPro2OK = !string.IsNullOrEmpty(pro2) && !pro2.Contains(RFIDinfo.NGflag) && IsProOK2;

                                                    displalyInfo.displayInfoMain(msg_Rfid);
                                                    GlobalVar.Laser_pros.ForEach(a =>
                                                    {
                                                        if (a.ProNo == 2)
                                                        {
                                                            a.ProId = pro2;
                                                            if (!IsPro2OK)
                                                            {
                                                                a.Result_up = e_Result.进料读卡NG.ToString();
                                                            }
                                                        }
                                                    });
                                                    if (GlobalVar.userConfig.UploadInfo.IsUploadUrl)
                                                    {
                                                        if (!string.IsNullOrEmpty(GlobalVar.userConfig.UploadInfo.url_CheckUpload))
                                                        {
                                                            UploadInterface.upload_CheckUpload(pro2);
                                                        }
                                                    }
                                                    if (GlobalVar.Laser_pros.Where(a => a.Result_up.Contains("NG") && a.ProNo == 2).FirstOrDefault() != null)///单平台2+平台1读卡NG
                                                        e_Cut = e_Flow_Cut.放行治具;
                                                    else
                                                        e_Cut = e_Flow_Cut.撕膜;
                                                }
                                            }
                                            else
                                            {
                                                GlobalVar.IsEndWork = false;
                                                e_Cut = e_Flow_Cut.撕膜;
                                            }

                                        }
                                    }
                                    break;
                                case e_Flow_Cut.撕膜:
                                    {
                                        if (Input_CardEx2[(int)e_input_extCard2.上输送治具检测1] && Input_CardEx2[(int)e_input_extCard2.上输送治具检测2])
                                        {
                                            GlobalMotion.TipInfo($"入料信号检测超时，请检查是否堆料?");
                                        }

                                        if (GlobalVar.userConfig.isCutFinishOK)
                                        {
                                            GlobalVar.Laser_pros.ForEach(pro =>
                                            {
                                                if (e_CurPlate == e_platePro.双平台有)
                                                {
                                                    pro.Result_Cut = e_Result.撕膜OK.ToString();
                                                }
                                                else
                                                {
                                                    if (pro.ProNo == (int)e_CurPlate)
                                                    {
                                                        pro.Result_Cut = e_Result.撕膜OK.ToString();
                                                    }
                                                    else
                                                        pro.Result_Cut = e_Result.撕膜NG.ToString();
                                                }
                                            });
                                            e_Cut = e_Flow_Cut.放行治具;
                                            break;
                                        }
                                        IsCutOver = true;
                                        var nres = Step_Cut(e_Step_Cut.松开膜, e_CurPlate);
                                        if (nres != 1)
                                        {
                                            MachineState(e_MachineStatus.异常急停, $"{e_Cut.ToString()}:松膜");
                                            continue;
                                        }

                                        nres = Step_Cut(e_Step_Cut.下降压住产品, e_CurPlate);
                                        if (nres != 1)
                                        {
                                            MachineState(e_MachineStatus.异常急停, $"{e_Cut.ToString()}:下降压住产品");
                                            continue;
                                        }
                                        nres = Step_Cut(e_Step_Cut.移至撕膜等料位, e_CurPlate);
                                        if (nres != 1)
                                        {
                                            MachineState(e_MachineStatus.异常急停, $"{e_Cut.ToString()}:移至撕膜等料位");
                                            continue;
                                        }

                                        nres = Step_Cut(e_Step_Cut.移至撕膜水平位, e_CurPlate);
                                        if (nres != 1)
                                        {
                                            MachineState(e_MachineStatus.异常急停, $"{e_Cut.ToString()}:移至撕膜水平位");
                                            continue;
                                        }

                                        nres = Step_Cut(e_Step_Cut.移至夹膜位, e_CurPlate);
                                        if (nres != 1)
                                        {
                                            MachineState(e_MachineStatus.异常急停, $"{e_Cut.ToString()}:移至夹膜位");
                                            continue;
                                        }
                                        if (GlobalVar.motionConfig.clamp_Delay > 0)
                                            Thread.Sleep((int)GlobalVar.motionConfig.clamp_Delay);
                                        nres = Step_Cut(e_Step_Cut.夹住膜, e_CurPlate);
                                        if (nres != 1)
                                        {
                                            MachineState(e_MachineStatus.异常急停, $"{e_Cut.ToString()}:夹膜");
                                            continue;
                                        }

                                        nres = Step_Cut(e_Step_Cut.移至撕膜过度位, e_CurPlate);
                                        if (nres != 1)
                                        {
                                            MachineState(e_MachineStatus.异常急停, $"{e_Cut.ToString()}:移至撕膜过度位");
                                            continue;
                                        }

                                        nres = Step_Cut(e_Step_Cut.移至撕膜终点位, e_CurPlate);
                                        if (nres != 1)
                                        {
                                            MachineState(e_MachineStatus.异常急停, $"{e_Cut.ToString()}:移至撕膜终点位");
                                            continue;
                                        }
                                        nres = Step_Cut(e_Step_Cut.上升松开产品, e_CurPlate);
                                        if (nres != 1)
                                        {
                                            MachineState(e_MachineStatus.异常急停, $"{e_Cut.ToString()}:上升松开产品");
                                            continue;
                                        }
                                        GlobalVar.Laser_pros.ForEach(a =>
                                        {
                                            switch (e_CurPlate)
                                            {
                                                case e_platePro.平台1:
                                                    if (a.ProNo == 1)
                                                        a.Result_Cut = e_Result.撕膜OK.ToString();
                                                    break;
                                                case e_platePro.平台2:
                                                    if (a.ProNo == 2)
                                                        a.Result_Cut = e_Result.撕膜OK.ToString();
                                                    break;
                                                case e_platePro.双平台有:
                                                    if (a.ProNo == 2 || a.ProNo == 1)
                                                        a.Result_Cut = e_Result.撕膜OK.ToString();
                                                    break;
                                            }
                                        });
                                        GlobalVar.Cut_Finish = true;
                                        nres = Step_Cut(e_Step_Cut.移至撕膜垃圾位, e_CurPlate);
                                        if (nres != 1)
                                        {
                                            MachineState(e_MachineStatus.异常急停, $"{e_Cut.ToString()}:移至撕膜垃圾位");
                                            continue;
                                        }
                                        GlobalMotion.CardExt_1.setOut((ushort)e_output_extCard1.撕膜垃圾位吹膜, e_out_OnOff.off);
                                        nres = Step_Cut(e_Step_Cut.松开膜, e_CurPlate);
                                        if (nres != 1)
                                        {
                                            MachineState(e_MachineStatus.异常急停, $"{e_Cut.ToString()}:松开膜");
                                            continue;
                                        }
                                        nres = Step_Cut(e_Step_Cut.Z轴上下动, e_CurPlate);
                                        if (nres != 1)
                                        {
                                            MachineState(e_MachineStatus.异常急停, $"{e_Cut.ToString()}:Z轴上下动");
                                            continue;
                                        }
                                        nres = Step_Cut(e_Step_Cut.吹气除膜, e_CurPlate);
                                        if (nres != 1)
                                        {
                                            MachineState(e_MachineStatus.异常急停, $"{e_Cut.ToString()}:吹气除膜");
                                            continue;
                                        }

                                        nres = Step_Cut(e_Step_Cut.移至撕膜等料位, e_CurPlate);
                                        if (nres != 1)
                                        {
                                            MachineState(e_MachineStatus.异常急停, $"{e_Cut.ToString()}:移至撕膜等料位");
                                            continue;
                                        }

                                        e_Cut = e_Flow_Cut.等待有工装到达;
                                    }
                                    break;
                                case e_Flow_Cut.放行治具:
                                    {
                                        if (!GlobalVar.IsOldTest && !IsCutOver && !CMachine.Instance.IsTestModel)
                                        {
                                            GlobalVar.Cut_Finish = true;
                                            IsCutOver = true;
                                        }
                                        e_Cut = e_Flow_Cut.等待有工装到达;
                                    }
                                    break;

                            }
                            if (logFlow != e_Cut.ToString())
                            {
                                logFlow = e_Cut.ToString();
                                displalyInfo.displayInfoMain($"撕膜流程:{e_CurPlate.ToString()}:" + logFlow);
                            }
                        }
                    }
                    else
                        IsCutOver = false;
                }
            }
            catch (Exception ex)
            {
                displalyInfo.displayInfoMain("Task_Laser" + ex.Message);
            }
        }

        /// <summary>
        /// 单步-撕膜
        /// </summary>
        /// <param name="e_Laser"></param>
        /// <param name="e_Plate"></param>
        /// <returns></returns>
        public static int Step_Cut(e_Step_Cut e_StepCut, e_platePro e_Plate = e_platePro.平台1, e_MachineStatus e_Staus = e_MachineStatus.暂停控制)
        {
            try
            {
                displalyInfo.displayInfoMain(e_StepCut.ToString());
                switch (e_Staus)
                {
                    case e_MachineStatus.无控制:
                        break;
                    case e_MachineStatus.暂停控制:
                        {
                            var nstop = MachineState(e_MachineStatus.暂停控制);
                            if (nstop != 1)
                                return -1;
                        }
                        break;
                }

                switch (e_StepCut)
                {
                    case e_Step_Cut.移至撕膜等料位:
                        {
                            //先 走Z轴安全高度  再两R+两X+Y轴 +Z轴
                            var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.撕膜Z, GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜安全位].Z, 1, true);
                            if (!bres)
                                return -1;

                            List<SigleAxis> posList = new List<SigleAxis>();
                            posList.Add(new SigleAxis()
                            {
                                IsAbs = true,
                                nAxis = (int)e_card1_axis.撕膜X,
                                pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜等料位].X,
                                velrate = 1
                            });
                            posList.Add(new SigleAxis()
                            {
                                IsAbs = true,
                                nAxis = (int)e_card1_axis.撕膜Y,
                                pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜等料位].Y,
                                velrate = 1
                            });
                            posList.Add(new SigleAxis()
                            {
                                IsAbs = true,
                                nAxis = (int)e_card1_axis.撕膜R1,
                                pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜等料位].R1,
                                velrate = 1
                            });
                            posList.Add(new SigleAxis()
                            {
                                IsAbs = true,
                                nAxis = (int)e_card1_axis.撕膜R2,
                                pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜等料位].R2,
                                velrate = 1
                            });

                            bres = GlobalMotion.toPostionMutil(posList);
                            if (!bres)
                                return -1;

                            //先 Z轴  再两R+两X+Y轴
                            bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.撕膜Z, GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜等料位].Z, 1, true);

                            return bres ? 1 : -1;
                        }
                        break;
                    case e_Step_Cut.移至撕膜水平位:
                        {
                            //先 Z轴  再两R+两X+Y轴
                            var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.撕膜Z, GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜水平位].Z, 1, true);
                            if (!bres)
                                return -1;
                            List<SigleAxis> posList = new List<SigleAxis>();

                            posList.Add(new SigleAxis()
                            {
                                IsAbs = true,
                                nAxis = (int)e_card1_axis.撕膜X,
                                pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜水平位].X,
                                velrate = 1
                            });
                            posList.Add(new SigleAxis()
                            {
                                IsAbs = true,
                                nAxis = (int)e_card1_axis.撕膜Y,
                                pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜水平位].Y,
                                velrate = 1
                            });
                            switch (e_Plate)
                            {
                                case e_platePro.平台1:
                                    posList.Add(new SigleAxis()
                                    {
                                        IsAbs = true,
                                        nAxis = (int)e_card1_axis.撕膜R1,
                                        pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜水平位].R1,
                                        velrate = 1
                                    });
                                    break;
                                case e_platePro.平台2:
                                    posList.Add(new SigleAxis()
                                    {
                                        IsAbs = true,
                                        nAxis = (int)e_card1_axis.撕膜R2,
                                        pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜水平位].R2,
                                        velrate = 1
                                    });
                                    break;
                                case e_platePro.双平台有:
                                    posList.Add(new SigleAxis()
                                    {
                                        IsAbs = true,
                                        nAxis = (int)e_card1_axis.撕膜R1,
                                        pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜水平位].R1,
                                        velrate = 1
                                    });
                                    posList.Add(new SigleAxis()
                                    {
                                        IsAbs = true,
                                        nAxis = (int)e_card1_axis.撕膜R2,
                                        pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜水平位].R2,
                                        velrate = 1
                                    });
                                    break;
                            }

                            bres = GlobalMotion.toPostionMutil(posList);
                            return bres ? 1 : -1;
                        }
                        break;
                    case e_Step_Cut.移至夹膜位:
                        {
                            //先 Z轴  再两R+两X+Y轴
                            var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.撕膜Z, GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.夹膜位].Z, 1, true);
                            if (!bres)
                                return -1;
                            List<SigleAxis> posList = new List<SigleAxis>();
                            posList.Add(new SigleAxis()
                            {
                                IsAbs = true,
                                nAxis = (int)e_card1_axis.撕膜X,
                                pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.夹膜位].X,
                                velrate = 1
                            });
                            posList.Add(new SigleAxis()
                            {
                                IsAbs = true,
                                nAxis = (int)e_card1_axis.撕膜Y,
                                pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.夹膜位].Y,
                                velrate = 1
                            });
                            switch (e_Plate)
                            {
                                case e_platePro.平台1:
                                    posList.Add(new SigleAxis()
                                    {
                                        IsAbs = true,
                                        nAxis = (int)e_card1_axis.撕膜R1,
                                        pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.夹膜位].R1,
                                        velrate = 1
                                    });
                                    //posList.Add(new SigleAxis()
                                    //{
                                    //    IsAbs = true,
                                    //    nAxis = (int)e_card1_axis.撕膜R2,
                                    //    pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜等料位].R2,
                                    //    velrate = 1
                                    //});
                                    break;
                                case e_platePro.平台2:
                                    posList.Add(new SigleAxis()
                                    {
                                        IsAbs = true,
                                        nAxis = (int)e_card1_axis.撕膜R2,
                                        pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.夹膜位].R2,
                                        velrate = 1
                                    });
                                    break;
                                case e_platePro.双平台有:
                                    posList.Add(new SigleAxis()
                                    {
                                        IsAbs = true,
                                        nAxis = (int)e_card1_axis.撕膜R1,
                                        pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.夹膜位].R1,
                                        velrate = 1
                                    });
                                    posList.Add(new SigleAxis()
                                    {
                                        IsAbs = true,
                                        nAxis = (int)e_card1_axis.撕膜R2,
                                        pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.夹膜位].R2,
                                        velrate = 1
                                    });
                                    break;
                            }

                            bres = GlobalMotion.toPostionMutil(posList);
                            return bres ? 1 : -1;
                        }
                        break;
                    case e_Step_Cut.移至撕膜终点位:
                        {
                            //先 Z轴  再两R+两X+Y轴
                            var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.撕膜Z, GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜安全位].Z, 1, true);
                            if (!bres)
                                return -1;
                            List<SigleAxis> posList = new List<SigleAxis>();
                            posList.Add(new SigleAxis()
                            {
                                IsAbs = true,
                                nAxis = (int)e_card1_axis.撕膜X,
                                pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜终点位].X,
                                velrate = 1
                            });
                            posList.Add(new SigleAxis()
                            {
                                IsAbs = true,
                                nAxis = (int)e_card1_axis.撕膜Y,
                                pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜终点位].Y,
                                velrate = 1
                            });
                            switch (e_Plate)
                            {
                                case e_platePro.平台1:
                                    posList.Add(new SigleAxis()
                                    {
                                        IsAbs = true,
                                        nAxis = (int)e_card1_axis.撕膜R1,
                                        pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜终点位].R1,
                                        velrate = 1
                                    });
                                    //posList.Add(new SigleAxis()
                                    //{
                                    //    IsAbs = true,
                                    //    nAxis = (int)e_card1_axis.撕膜R2,
                                    //    pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜等料位].R2,
                                    //    velrate = 1
                                    //});
                                    break;
                                case e_platePro.平台2:
                                    //posList.Add(new SigleAxis()
                                    //{
                                    //    IsAbs = true,
                                    //    nAxis = (int)e_card1_axis.撕膜R1,
                                    //    pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜等料位].R1,
                                    //    velrate = 1
                                    //});
                                    posList.Add(new SigleAxis()
                                    {
                                        IsAbs = true,
                                        nAxis = (int)e_card1_axis.撕膜R2,
                                        pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜终点位].R2,
                                        velrate = 1
                                    });
                                    break;
                                case e_platePro.双平台有:
                                    posList.Add(new SigleAxis()
                                    {
                                        IsAbs = true,
                                        nAxis = (int)e_card1_axis.撕膜R1,
                                        pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜终点位].R1,
                                        velrate = 1
                                    });
                                    posList.Add(new SigleAxis()
                                    {
                                        IsAbs = true,
                                        nAxis = (int)e_card1_axis.撕膜R2,
                                        pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜终点位].R2,
                                        velrate = 1
                                    });
                                    break;
                            }

                            bres = GlobalMotion.toPostionMutil(posList);
                            if (!bres)
                                return -1;
                            bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.撕膜Z, GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜终点位].Z, 1, true);

                            return bres ? 1 : -1;
                        }
                        break;
                    case e_Step_Cut.移至撕膜垃圾位:
                        {
                            //先 走Z轴安全高度  再两R+两X+Y轴 +Z轴
                            var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.撕膜Z, GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜安全位].Z, 1, true);
                            if (!bres)
                                return -1;
                            List<SigleAxis> posList = new List<SigleAxis>();
                            posList.Add(new SigleAxis()
                            {
                                IsAbs = true,
                                nAxis = (int)e_card1_axis.撕膜X,
                                pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜垃圾位].X,
                                velrate = 1
                            });
                            posList.Add(new SigleAxis()
                            {
                                IsAbs = true,
                                nAxis = (int)e_card1_axis.撕膜Y,
                                pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜垃圾位].Y,
                                velrate = 1
                            });
                            switch (e_Plate)
                            {
                                case e_platePro.平台1:
                                    posList.Add(new SigleAxis()
                                    {
                                        IsAbs = true,
                                        nAxis = (int)e_card1_axis.撕膜R1,
                                        pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜垃圾位].R1,
                                        velrate = 1
                                    });
                                    //posList.Add(new SigleAxis()
                                    //{
                                    //    IsAbs = true,
                                    //    nAxis = (int)e_card1_axis.撕膜R2,
                                    //    pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜等料位].R2,
                                    //    velrate = 1
                                    //});
                                    break;
                                case e_platePro.平台2:
                                    //posList.Add(new SigleAxis()
                                    //{
                                    //    IsAbs = true,
                                    //    nAxis = (int)e_card1_axis.撕膜R1,
                                    //    pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜等料位].R1,
                                    //    velrate = 1
                                    //});
                                    posList.Add(new SigleAxis()
                                    {
                                        IsAbs = true,
                                        nAxis = (int)e_card1_axis.撕膜R2,
                                        pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜垃圾位].R2,
                                        velrate = 1
                                    });
                                    break;
                                case e_platePro.双平台有:
                                    posList.Add(new SigleAxis()
                                    {
                                        IsAbs = true,
                                        nAxis = (int)e_card1_axis.撕膜R1,
                                        pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜垃圾位].R1,
                                        velrate = 1
                                    });
                                    posList.Add(new SigleAxis()
                                    {
                                        IsAbs = true,
                                        nAxis = (int)e_card1_axis.撕膜R2,
                                        pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜垃圾位].R2,
                                        velrate = 1
                                    });
                                    break;
                            }

                            bres = GlobalMotion.toPostionMutil(posList);
                            if (!bres)
                                return -1;

                            //最后走 Z轴 
                            bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.撕膜Z, GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜垃圾位].Z, 1, true);

                            return bres ? 1 : -1;

                        }
                        break;
                    case e_Step_Cut.移至撕膜过度位:
                        {
                            //先 Z轴  再两R+两X+Y轴
                            var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.撕膜Z, GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜过度位].Z, 1, true);
                            if (!bres)
                                return -1;
                            List<SigleAxis> posList = new List<SigleAxis>();
                            posList.Add(new SigleAxis()
                            {
                                IsAbs = true,
                                nAxis = (int)e_card1_axis.撕膜X,
                                pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜过度位].X,
                                velrate = 1
                            });
                            posList.Add(new SigleAxis()
                            {
                                IsAbs = true,
                                nAxis = (int)e_card1_axis.撕膜Y,
                                pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜过度位].Y,
                                velrate = 1
                            });
                            switch (e_Plate)
                            {
                                case e_platePro.平台1:
                                    posList.Add(new SigleAxis()
                                    {
                                        IsAbs = true,
                                        nAxis = (int)e_card1_axis.撕膜R1,
                                        pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜过度位].R1,
                                        velrate = 1
                                    });
                                    break;
                                case e_platePro.平台2:
                                    //posList.Add(new SigleAxis()
                                    //{
                                    //    IsAbs = true,
                                    //    nAxis = (int)e_card1_axis.撕膜R1,
                                    //    pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜等料位].R1,
                                    //    velrate = 1
                                    //});
                                    posList.Add(new SigleAxis()
                                    {
                                        IsAbs = true,
                                        nAxis = (int)e_card1_axis.撕膜R2,
                                        pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜过度位].R2,
                                        velrate = 1
                                    });
                                    break;
                                case e_platePro.双平台有:
                                    posList.Add(new SigleAxis()
                                    {
                                        IsAbs = true,
                                        nAxis = (int)e_card1_axis.撕膜R1,
                                        pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜过度位].R1,
                                        velrate = 1
                                    });
                                    posList.Add(new SigleAxis()
                                    {
                                        IsAbs = true,
                                        nAxis = (int)e_card1_axis.撕膜R2,
                                        pos = GlobalVar.motionConfig.Cut_pos[(int)e_PosCut.撕膜过度位].R2,
                                        velrate = 1
                                    });
                                    break;
                            }

                            bres = GlobalMotion.toPostionMutil(posList);
                            if (!bres)
                            {
                                int a = 1;
                            }
                            return bres ? 1 : -1;
                        }
                        break;
                    case e_Step_Cut.夹住膜:
                        {
                            var nres = -1;
                            if (e_Plate == e_platePro.平台1)
                            {
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.撕膜气缸1, e_out_OnOff.on);
                                Thread.Sleep(GlobalVar.userConfig.clampTime);
                                return 1;
                            }
                            else if (e_Plate == e_platePro.平台2)
                            {
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.撕膜气缸2, e_out_OnOff.on);
                                Thread.Sleep(GlobalVar.userConfig.clampTime);
                                return 1;
                            }
                            else if (e_Plate == e_platePro.双平台有)
                            {
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.撕膜气缸1, e_out_OnOff.on);
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.撕膜气缸2, e_out_OnOff.on);
                                Thread.Sleep(GlobalVar.userConfig.clampTime);
                                return 1;
                            }
                        }
                        break;
                    case e_Step_Cut.松开膜:
                        {
                            var nres = -1;
                            if (e_Plate == e_platePro.平台1)
                            {
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.撕膜气缸1, e_out_OnOff.off);
                                Thread.Sleep(GlobalVar.userConfig.clampTime);
                                return 1;
                            }
                            else if (e_Plate == e_platePro.平台2)
                            {
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.撕膜气缸2, e_out_OnOff.off);
                                Thread.Sleep(GlobalVar.userConfig.clampTime);
                                return 1;
                            }
                            else if (e_Plate == e_platePro.双平台有)
                            {
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.撕膜气缸1, e_out_OnOff.off);
                                GlobalMotion.CardExt_2.setOut((int)e_output_extCard2.撕膜气缸2, e_out_OnOff.off);
                                Thread.Sleep(GlobalVar.userConfig.clampTime);
                                return 1;
                            }
                        }
                        break;
                    case e_Step_Cut.Z轴上下动:
                        if (GlobalVar.motionConfig.CutNG_time > 0)
                        {
                            var curZpos = GlobalMotion.Card_1.AxisList[(int)e_card1_axis.撕膜Z].m_AxisSts.CurrPosi;
                            for (int nTime = 0; nTime < GlobalVar.motionConfig.CutNG_time; nTime++)
                            {
                                var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.撕膜Z, GlobalVar.motionConfig.CutNG_HeightZ, 1, true);
                                if (bres)
                                    return -1;
                                bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.撕膜Z, GlobalVar.motionConfig.CutNG_LowZ, 1, true);
                                if (bres)
                                    return -1;
                                Thread.Sleep(GlobalVar.motionConfig.CutNG_Delay);
                            }
                            var bres1 = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.撕膜Z, curZpos, 1, true);
                            if (bres1)
                                return -1;
                        }
                        else
                            return 1;
                        break;
                    case e_Step_Cut.吹气除膜:
                        {
                            var nres = -1;
                            var bres = false;
                            var vel = 1.0;
                            GlobalMotion.CardExt_1.setOut((ushort)e_output_extCard1.撕膜垃圾位吹膜, e_out_OnOff.off);
                            Thread.Sleep(GlobalVar.motionConfig.airCutTime);
                            GlobalMotion.CardExt_1.setOut((ushort)e_output_extCard1.撕膜垃圾位吹膜, e_out_OnOff.on);
                            return 1;
                        }
                        break;
                    case e_Step_Cut.吹气除尘:
                        {
                            GlobalMotion.CardExt_1.setOut((ushort)e_output_extCard1.撕膜后除尘, e_out_OnOff.off);
                            Thread.Sleep(GlobalVar.userConfig.airCutTime);
                            GlobalMotion.CardExt_1.setOut((ushort)e_output_extCard1.撕膜后除尘, e_out_OnOff.on);
                            return 1;
                        }
                        break;
                    case e_Step_Cut.下降压住产品:
                        {
                            var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.一段压产品Z, GlobalVar.motionConfig.ProZ_down, 1, true);
                            return bres ? 1 : -1;
                        }
                        break;
                    case e_Step_Cut.上升松开产品:
                        {
                            var bres = GlobalMotion.toPosition((int)e_Card.Card1, (int)e_card1_axis.一段压产品Z, GlobalVar.motionConfig.ProZ_up, 1, true);
                            return bres ? 1 : -1;
                        }
                        break;
                }

                return -1;
            }
            catch (Exception ex)
            {
                displalyInfo.displayInfoMain("Step_Laser" + ex.Message);
                return -1;
            }
        }

    }
}
